/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package validation;

import javax.swing.text.*;
/**
 *
 * @author Usuario
 */
public class DocumentSizeFilter extends PlainDocument {

    int maxCharacters;

    public DocumentSizeFilter(int maxChars) {
        this.maxCharacters = maxChars;
    }
    
    @Override
    public void insertString(int offs, String str, AttributeSet a)
            throws BadLocationException {
        
        if (super.getLength() + str.length() <= maxCharacters) {
            super.insertString(offs, str, a);
        }
    }
}
